import json
import os
import yaml


class FileHandler:

    @staticmethod
    def get_root():
        current_dir = os.path.join(__file__)
        root = os.path.dirname(current_dir)
        return root

    @staticmethod
    def parse_json(filepath):
        """
        处理json文件
        :param filepath:
        :return:
        """
        testdata = []
        os.path.join(FileHandler.get_root(), filepath)
        with open(filepath, mode='r', encoding='utf8')as f:
            data = json.load(f)
            for obj in data:
                vals = []
                for k, v in obj.items():
                    vals.append(v)
                testdata.append(tuple(vals))
        return testdata

    @staticmethod
    def parse_yaml(yamlpath):
        """
        处理yaml文件
        :param yamlpath:
        :return:
        """
        os.path.join(FileHandler.get_root(), yamlpath)
        with open(yamlpath, mode='r', encoding='utf8')as f:
            data = yaml.load(f.read(), Loader=yaml.Loader)
            new_data = dict(data)
        return new_data
